﻿using System.Web;
using System.Web.UI;
using Baby.Growup.Common;
using Baby.GrowUp.Model;

namespace Baby.GrowUp.Web.Admin.Base
{
    public class PageBase : Page
	{
        /// <summary>
        /// 获取登录用户
        /// </summary>
        protected Users CurrentUser
        {
            get
            {
                string userJson = Cache["CurrentUser"] as string;

                if (!string.IsNullOrWhiteSpace(userJson))
                {
                    return userJson.ToObject<Users>();
                }

                HttpCookie cookie = Request.Cookies["Baby_GrowUp_UserId"];
                if (cookie == null)
                {
                    return null;
                }

                string uid = cookie.Value;

                if (string.IsNullOrWhiteSpace(uid))
                {
                    return null;
                }

                Users user = Users.GetUserByUserId(uid);

                if (user != null)
                {
                    Cache["CurrentUser"] = user.ToJsonString();
                    return user;
                }

                return null;
            }
        }
	}
}